<?php

class Article_IndexController extends Veneer_Controller_Module
{

 	function init()
	{
		$this->_dbArray =array('Article');
		$this->_moduleName = 'article';;
//		$this->_config_module;  // config object
		$this->_list_title = "My Articles";
		$this->_primary_table ='Article';;
		parent::init();
	}
   function indexAction()
    {
        $this->view->title = "Article List";

        $entry = new Article();
        $this->view->entries = $entry->fetchAll();
		print "<pre>";
		print_r($entry->test());
		print "</pre>";
		Zend_Layout::getLayout('index')
	        ->addRequest(new Zend_Layout_Request('menuZone', 'menu', 'block','article'));
	//	$this->menuZone='<li class="page_item"><a href="/zend/veneer/test" title="Contact">Add Article</a></li>';
		// listHelper

    }

    function menuAction()
    {
		static  $formArray = array();

        $this->view->title = "Add New Album";

		$this->addHelper($formArray);

    }

    function addAction()
    {
		static  $formArray = array();

		//		$this->addHelper($formArray);
		if (strtolower($_SERVER['REQUEST_METHOD']) == 'post') {
			print "<pre>" . print_r($_POST, true) . "</pre>";

			$obj = new Article();
			$obj->insert($_POST);
		} 

       	$obj = new Article();
		$this->view->obj = $obj->createRow();
		$this->view->tags = "";
    }

function editAction()
{
    $this->view->title = "Edit Album";
    $album = new Album();

    if (strtolower($_SERVER['REQUEST_METHOD']) == 'post') {


    	$id = (int)$this->_request->getPost('id');
    	$artist = $filter->filter($this->_request->getPost('artist'));
    	$artist = trim($artist);
    	$title = trim($filter->filter($this->_request->getPost('title')));

        if ($id !== false) {
            if ($artist != '' && $title != '') {
				$data = array(
				    'artist' => $artist,
				    'title'  => $title,
				);
				$where = 'id = ' . $id;
				$album->update($data, $where);

	    	    $this->_redirect('/');
	    	    return;
            } else {
                $this->view->album = $album->fetchRow('id='.$id);
	        }
        }
    } else {
        // album id should be $params['id']
        $id = (int)$this->_request->getParam('id', 0);
	    if ($id > 0) {
	        $this->view->album = $album->fetchRow('id='.$id);
	    }
    }

    // additional view fields required by form
    $this->view->action = 'edit';
    $this->view->buttonText = 'Update';

    $this->render();
}

    function deleteAction()
    {
        $this->view->title = "Delete Album";

        $album = new Album();
        if (strtolower($_SERVER['REQUEST_METHOD']) == 'post') {
            Zend_Loader::loadClass('Zend_Filter_Alpha');
            $filter = new Zend_Filter_Alpha();

            $id = (int)$this->_request->getPost('id');
            $del = $filter->filter($this->_request->getPost('del'));

            if ($del == 'Yes' && $id > 0) {
	            $where = 'id = ' . $id;
				$rows_affected = $album->delete($where);
	        }
        } else {
            $id = (int)$this->_request->getParam('id');
		    if ($id > 0) {
		        // only render if we have an id and can find the album.
		        $this->view->album = $album->fetchRow('id='.$id);

		        if ($this->view->album->id > 0) {
                    $this->render();
                    return;
		        }
		    }
        }

        // redirect back to the album list unless we have rendered the view
   	    $this->_redirect('/');
    }

}